package com.cet.designpatterns.singleton.type4;

/**
 * @program: algorithm
 * @description:
 * @author: 陈恩涛
 * @create: 2021-08-30 23:15
 **/
public class Singleton {

    private static Singleton instance;

    private Singleton() {

    }

    //当使用到该方法时，才去创建instance
    //饿汉式
    //加synchronized锁，解决线程安全问题
    public static synchronized Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}
